/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package alloytoy;

import edu.mit.csail.sdg.alloy4.Err;
import edu.mit.csail.sdg.alloy4compiler.ast.Module;
import edu.mit.csail.sdg.alloy4compiler.parser.CompUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * AlloyFunctions represents some data related  with the model.
 * @author Daniel
 */
public class AlloyFunctions {
    String fileName;
    Module fileChecked;
    MyReporter rep;
    ArrayList<String> diffSigs;

    public AlloyFunctions(){
        diffSigs = new ArrayList<String>();
    }
    
    public void initAll(String fName) throws IOException{
        fileName = fName;
        rep = new MyReporter();
        try {
            fileChecked = CompUtil.parseEverything_fromFile(rep, null, fileName);
            //Warnings are fatal
            if(rep.getWarningCount()!=0){
                ArrayList<String> tmp = rep.getWarnings();
                for(int i=0; i<tmp.size(); i++)
                    System.out.println(tmp.get(i));
                System.out.println("FILENAME: "+fileName);
                Util.PrintFile(fileName);
                System.exit(0);
            }
        } catch (Err ex) {
            System.out.println(ex);
            System.out.println("FILENAME: "+fileName);
            Util.PrintFile(fileName);
            System.exit(0);
        }
    }

    public Module getModule(){ return fileChecked; }

    public MyReporter getReport(){ return rep; }
}
